package com.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ResourceBundle;

public class DBUtil {
	private static ResourceBundle rb;
	private static String DRIVER;
	private static String URL;
	private static String USERNAME;
	private static String PASSWORD;
	
	static {
		rb = ResourceBundle.getBundle("com.util.db_config");
		DRIVER = rb.getString("db_driver");
		URL = rb.getString("db_url");
		USERNAME = rb.getString("db_username");
		PASSWORD = rb.getString("db_password");
	}
	
	public static Connection getConnection() {
		Connection conn = null;
		
		try {
			Class.forName(DRIVER);
			conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return conn;
	}
	
	public static void close(Connection conn) {
		try {
			if(conn != null) {
				conn.close();
			} 
		} catch(Exception ex) {
			ex.printStackTrace();
		}
	}
	
	public static void close(Statement stmt){
		try {
			if(stmt != null) {
				stmt.close();
			}
		} catch(Exception ex) {
			ex.printStackTrace();
		}
	}
	
	public static void close(ResultSet rs) {
		try {
			if(rs != null) {
				rs.close();
			}
		} catch(Exception ex) {
			ex.printStackTrace();
		}
	}

}
